﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EarTag.API.Application.MediatorCommand.BodyMeasureCommand;
using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;

namespace S.EarTag.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BodyMeasureController : BaseController
    {
        private readonly IMediator _mediator;
        public BodyMeasureController(IMediator mediator,MySqlDbContext _db):base(_db)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 根据主键Id删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> DeleteBodyMeasure(int id)
        {
            BodyMeasureDeleteCommand command = new BodyMeasureDeleteCommand();
            command.BodyMeasureId = id;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 添加体尺测量数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddBodyMeasure(BodyMeasureCreateCommand command)
        {
            command.CreateBy = UserStrategyDto.UserTrueName;
            command.CreateDate = DateTime.Now;
            command.UpdateBy = "";
            command.UpdateDate = "";
            var model=await _mediator.Send(command);
            return Ok(model);
        }
        /// <summary>
        /// 修改体尺测量数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdBodyMeasure(BodyMeasureUpdCommand command)
        {
            command.UpdateBy = UserStrategyDto.UserTrueName;
            command.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var model=await _mediator.Send(command);
            return Ok(model);
        }
        /// <summary>
        /// 批量删除体尺测量数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> BatchRemoveBodyMeasure(BodyMeasureBatchRemoveCommand command)
        {
            var result=await _mediator.Send(command);
            return Ok(result);
        }
    }
}
